package com.zhangjian.test1;

public class DeadLockTest {
    private  Object object1 = new Object();
    private  Object object2 = new Object();
    private  void lock(){
        Thread thread1 =  new Thread(
                 () ->{
                     synchronized (object1) {
                         System.out.println("thread1 锁定了 object1");
                         synchronized (object2) {
                             System.out.println("thread1 锁定了 object2");
                         }
                     };
                 }
         );
       Thread thread2 = new Thread(
               () ->{
                   synchronized (object2) {
                       System.out.println("thread2 锁定了 object2");
                       synchronized (object1) {
                           System.out.println("thread2 锁定了 object1");
                       }
                   };
               }
       );
        thread1.start();
        thread2.start();
    }

    public static void main(String[] args) {
        new DeadLockTest().lock();
    }
}
